package com.ethan.valid.config;

import com.ethan.valid.vo.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: ethan.liu
 * @Date: 2020/10/15 17:27
 */
@ControllerAdvice
@Slf4j
public class ComExceptionHandler {
    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    @ResponseBody
    public R handleBindException(MethodArgumentNotValidException e) throws BindException {
        R r = new R(401,null,e.getMessage());
        log.info("BindException", e);
        return r;
    }

}
